package com.atguigu.jxc.controller;

import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.domain.SuccessCode;
import com.atguigu.jxc.entity.Goods;
import com.atguigu.jxc.service.GoodsTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author lfh
 * @version 1.0
 * @date 2021/5/13 18:17
 */
@RestController
@RequestMapping("/goodsType")
public class GoodsTypeController {

    @Autowired
    private GoodsTypeService goodsTypeService;

    //http://localhost:8080/goodsType/loadGoodsType
    /**
     * 查询商品所有分类
     * @return
     */
    @PostMapping("/loadGoodsType")
    public String loadGoodsType(){
        return goodsTypeService.loadGoodsType();
    }


    // http://localhost:8080/goodsType/save
    @PostMapping("/save")
    public ServiceVO save(String goodsTypeName,Integer pId){
        try {
            goodsTypeService.save(goodsTypeName,pId);
        } catch (Exception e) {
            return new ServiceVO(400, "保存失败");
        }
        return new ServiceVO<>(SuccessCode.SUCCESS_CODE, SuccessCode.SUCCESS_MESS);
    }

//    // http://localhost:8080/goodsType/delete
//
//    /**
//     * 根据Id删除分类
//     * @param goodsTypeId
//     * @return
//     */
    @PostMapping("/delete")
    public ServiceVO delete(Integer goodsTypeId){
        try {
            goodsTypeService.deleteById(goodsTypeId);
        } catch (Exception e) {
            return new ServiceVO(400, "删除失败");
        }
        return new ServiceVO<>(SuccessCode.SUCCESS_CODE, SuccessCode.SUCCESS_MESS);
    }


}
